﻿/**
 * Copyright (c) 2008 Justin Etheredge http://www.codethinked.com
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Microsoft Public License (Ms-PL)
 * which accompanies this distribution, and is available at
 * http://www.opensource.org/licenses/ms-pl.html
 * If redistributing this code, this entire header must remain intact.
 * 
 * Some of the code in this application has been taken 
 * from the following sources (all of which are licensed under
 * the Ms-PL):
 * Matt Warren's Blog: http://blogs.msdn.com/mattwar/
 * MSDN: http://msdn2.microsoft.com/en-us/library/bb546158.aspx
 */

using LinqToSimpleDB;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Linq;

namespace LinqToSimpleDBTest
{
    
    
    /// <summary>
    ///This is a test class for SimpleDBItemTest and is intended
    ///to contain all SimpleDBItemTest Unit Tests
    ///</summary>
  [TestClass()]
  public class SimpleDBItemTest
  {


    private TestContext testContextInstance;

    /// <summary>
    ///Gets or sets the test context which provides
    ///information about and functionality for the current test run.
    ///</summary>
    public TestContext TestContext
    {
      get
      {
        return testContextInstance;
      }
      set
      {
        testContextInstance = value;
      }
    }

    #region Additional test attributes
    // 
    //You can use the following additional attributes as you write your tests:
    //
    //Use ClassInitialize to run code before running the first test in the class
    //[ClassInitialize()]
    //public static void MyClassInitialize(TestContext testContext)
    //{
    //}
    //
    //Use ClassCleanup to run code after all tests in a class have run
    //[ClassCleanup()]
    //public static void MyClassCleanup()
    //{
    //}
    //
    //Use TestInitialize to run code before running each test
    //[TestInitialize()]
    //public void MyTestInitialize()
    //{
    //}
    //
    //Use TestCleanup to run code after each test has run
    //[TestCleanup()]
    //public void MyTestCleanup()
    //{
    //}
    //
    #endregion


    /// <summary>
    ///A test for WithAttribute
    ///</summary>
    [TestMethod()]
    public void WithAttributeTest()
    {
      var attribute1 = new SimpleDBAttribute("test", "test1");
      var attribute2 = new SimpleDBAttribute("test2", "test1");

      SimpleDBItem target = new SimpleDBItem()
        .WithAttribute(attribute1)
        .WithAttribute(attribute2);

      Assert.IsTrue(target.Attributes.Count == 2);

      Assert.AreEqual(target.Attributes["test"], attribute1);
      Assert.AreEqual(target.Attributes["test2"], attribute2);
    }

    /// <summary>
    ///A test for SimpleDBItem Constructor
    ///</summary>
    [TestMethod()]
    public void SimpleDBItemConstructorTest2()
    {
      SimpleDBItem target = new SimpleDBItem("test1", true);

      Assert.IsTrue(target.Name == "test1");
      Assert.IsTrue(target.IsDirty);

      target = new SimpleDBItem("test2", false);

      Assert.IsTrue(target.Name == "test2");
      Assert.IsTrue(target.IsDirty);
    }

    /// <summary>
    ///A test for SimpleDBItem Constructor
    ///</summary>
    [TestMethod()]
    public void SimpleDBItemConstructorTest1()
    {
      SimpleDBItem target = new SimpleDBItem("test1");
      Assert.IsTrue(target.Name == "test1");
      Assert.IsTrue(target.IsDirty);
    }

    /// <summary>
    ///A test for SimpleDBItem Constructor
    ///</summary>
    [TestMethod()]
    public void SimpleDBItemConstructorTest()
    {
      SimpleDBItem target = new SimpleDBItem();
      Assert.IsTrue(string.IsNullOrEmpty(target.Name));
      Assert.IsTrue(target.IsDirty);
    }

    /// <summary>
    ///A test for Attributes
    ///</summary>
    [TestMethod()]
    public void AttributesTest()
    {
      SimpleDBItem target = new SimpleDBItem();
      target.Attributes.Add(new SimpleDBAttribute("test1", "test"));
      target.Attributes.Add(new SimpleDBAttribute("test2", "test"));
      Assert.IsTrue(target.Attributes.Count == 2);
    }

    /// <summary>
    ///A test for IsDeleted
    ///</summary>
    [TestMethod()]
    public void IsDeletedTest()
    {
      IDeletable target = new SimpleDBItem();
      Assert.IsFalse(target.IsDeleted);
      target.MarkDeleted();
      Assert.IsTrue(target.IsDeleted);
    }

    /// <summary>
    ///A test for IsDirty
    ///</summary>
    [TestMethod()]
    public void IsDirtyTest()
    {
      IDirtyTrackable target = new SimpleDBItem();
      Assert.IsTrue(target.IsDirty);
      target.MarkClean();
      Assert.IsFalse(target.IsDirty);
      target.MarkDirty();
      Assert.IsTrue(target.IsDirty);
    }
  }
}
